package com.mjh.zhujianju.service.party.impl;

import com.google.common.collect.Lists;
import com.livew.framework.base.service.impl.BaseServiceImpl;
import com.mjh.zhujianju.dao.party.BuildingExamUserMapper;
import com.mjh.zhujianju.model.party.BuildingExamUserEO;
import com.mjh.zhujianju.service.party.BuildingExamUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author liuyang
 * @Description: 用户答题考试
 * @date 2018/8/18 14:16
 */
@Service
public class BuildingExamUserServiceImpl extends BaseServiceImpl<BuildingExamUserEO> implements BuildingExamUserService {

    @Autowired
    private BuildingExamUserMapper buildingExamUserMapper;

    public BuildingExamUserServiceImpl(BuildingExamUserMapper buildingExamUserMapper) {
        super(buildingExamUserMapper);
    }


    @Override
    public void insertByBatch(Map<Long,List<Long>> map,Long resultId) {
        BuildingExamUserEO buildingExamUserEO;
        List<BuildingExamUserEO> list = Lists.newArrayList();
        for (Long topicId : map.keySet()) {
            for (Long answerId : map.get(topicId)){
                buildingExamUserEO = new BuildingExamUserEO();
                buildingExamUserEO.setTopicId(topicId);
                buildingExamUserEO.setAnswerId(answerId);
                buildingExamUserEO.setResultId(resultId);
                buildingExamUserEO.setCreateTime(new Date());
                list.add(buildingExamUserEO);
            }
        }
        buildingExamUserMapper.insertByBatch(list);
    }

    @Override
    public List<BuildingExamUserEO> queryBuildingExamUserByExamId(Long examId) {
        return buildingExamUserMapper.queryBuildingExamUserByExamId(examId);
    }

    @Override
    public List<BuildingExamUserEO> queryBuildingExamUserByResultId(Long resultId) {
        BuildingExamUserEO buildingExamUserEO = new BuildingExamUserEO();
        buildingExamUserEO.setResultId(resultId);
        return buildingExamUserMapper.selectListByCondition(buildingExamUserEO);
    }
}
